/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.							  */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
/*----------------------------------------------------------------------------*/
#ifndef SENSORBASE_H_
#define SENSORBASE_H_

#include "chipobject/NiRio.h"
#include <stdio.h>

/**
 * Base class for all sensors.
 * Stores most recent status information as well as containing utility functions for checking
 * channels and error processing.
 */
class SensorBase {
public:
	static const unsigned kSystemClockTicksPerMicrosecond = 40;

	SensorBase::SensorBase(void);
	~SensorBase(void);
	unsigned int GetError( void );
	void ClearError(void);
	static void SetDefaultAnalogModule(unsigned slot);
	static void SetDefaultDigitalModule(unsigned slot);
	static void SetDefaultSolenoidModule(unsigned slot);
	static void DeleteSingletons(void);
protected:
	static unsigned GetDefaultAnalogModule(void) { return m_defaultAnalogModule; }
	static unsigned GetDefaultDigitalModule(void) { return m_defaultDigitalModule; }
	static unsigned GetDefaultSolenoidModule(void) { return m_defaultSolenoidModule; }
	static void CheckDigitalModule(unsigned slot);
	static void CheckRelayModule(unsigned slot);
	static void CheckPWMModule(unsigned slot);
	static void CheckSolenoidModule(unsigned slot);
	static void CheckAnalogModule(unsigned slot);
	static void CheckDigitalChannel(unsigned channel);
	static void CheckRelayChannel(unsigned channel);
	static void CheckPWMChannel(unsigned channel);
	static void CheckAnalogChannel(unsigned channel);
	static void CheckSolenoidChannel(unsigned channel);
	void AddToSingletonList(void);

	// TODO: Should this be static?
	tRioStatusCode status;

private:
	static unsigned m_defaultAnalogModule;
	static unsigned m_defaultDigitalModule;
	static unsigned m_defaultSolenoidModule;
	static SensorBase *m_singletonList;
	SensorBase *m_nextSingleton;
};

const unsigned kDigitalChannels = 14;
const unsigned kAnalogChannels = 8;
const unsigned kAnalogModules = 2;
const unsigned kSolenoidChannels = 8;
const unsigned kPwmChannels = 10;
const unsigned kRelayChannels = 8;
const unsigned kChassisSlots = 8;

#endif
